import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

Vue.use(Router)

//固定路由
export const constantRoutes = [
  //电话代表
  {
    path: '/',
    component: Layout,
    redirect: '/my_customer',
    meta: {title: '电话拜访', icon: 'el-icon-service'},
    role: '1',
    children: [
      {
        path: 'my_customer',
        component: () => import('../views/customer/index.vue'),
        meta: {title: '我的医生', icon: 'el-icon-user'}
      },
      {
        path: '/calling',
        component: () => import('../views/customer/calling.vue'),
        meta: {title: '信息填报', icon: 'el-icon-user'},
        hidden: true
      }
    ]
  },
  //微信代表
  {
    path: '/',
    component: Layout,
    redirect: '/weixinCustomer',
    meta: {title: '微信拜访', icon: 'el-icon-chat-line-round'},
    role: '2',
    children: [
      {
        path: '/weixinCustomer',
        component: () => import('../views/weixinCustomer/weixinCustomer'),
        meta: {title: '微信客户', icon: 'el-icon-chat-line-round'}
      },
    ]
  },
  //登录
  {
    path: '/login',
    component: () => import('../views/login/index.vue'),
    hidden: true
  },
  //404
  {
    path: '/404',
    component: () => import('../views/404.vue'),
    hidden: true
  },
  //拜访记录查询
  {
    path: '/comprehensiveQuery',
    component: Layout,
    meta: {title: '综合查询', icon: 'el-icon-chat-line-round'},
    children: [
      {
        path: '/visitRecordInquiry',
        component: () => import('../views/comprehensiveQuery/visitRecordInquiry'),
        meta: {title: '拜访记录查询'}
      },
    ]
  },
  //标签管理
  {
    path: '/labelManagement',
    component: Layout,
    redirect:'/basicLabel',
    meta: {title: '标签管理', icon: 'el-icon-chat-line-round'},
    children: [
      {
        path: '/basicLabel',
        component: () => import('../views/labelManagement/basicLabel'),
        meta: {title: '基础标签'},
      },
      {
        path: '/itemLabel',
        component: () => import('../views/labelManagement/itemLabel'),
        meta: {title: '项目标签'},
      },
    ]
  },
  //工单管理
  {
    path: '/workOrderAdministration',
    component: Layout,
    redirect:'/myWorkOrder',
    meta: {title: '工单管理', icon: 'el-icon-chat-line-round'},
    children: [
      {
        path: '/myWorkOrder',
        component: () => import('../views/workOrderAdministration/myWorkOrder'),
        meta: {title: '我的工单'},
      },
      {
        path: '/workOrderDetails',
        component: () => import('../views/workOrderAdministration/workOrderDetails'),
        meta: {title: '工单详情'},
        hidden: true
      },
      {
        path: '/allWorkOrders',
        component: () => import('../views/workOrderAdministration/allWorkOrders'),
        meta: {title: '全部工单'},
      },
    ]
  },
  //基础数据管理
  {
    path: '/basicDataManagement',
    component: Layout,
    redirect:'/hospitalManagement',
    meta: {title: '基础数据管理', icon: 'el-icon-chat-line-round'},
    children: [
      {
        path: '/hospitalManagement',
        component: () => import('../views/basicDataManagement/hospitalManagement'),
        meta: {title: '医院管理'},
      },
      {
        path: '/doctorManagement',
        component: () => import('../views/basicDataManagement/doctorManagement'),
        meta: {title: '医生管理'},
      },
    ]
  },
  //项目管理
  {
    path: '/projectManagement',
    component: Layout,
    redirect:'/pharmaceuticalEnterpriseManagement',
    meta: {title: '项目管理', icon: 'el-icon-chat-line-round'},
    children: [
      {
        path: '/pharmaceuticalEnterpriseManagement',
        component: () => import('../views/projectManagement/pharmaceuticalEnterpriseManagement'),
        meta: {title: '药企管理'},
      },
      {
        path: '/projectListManagement',
        component: () => import('../views/projectManagement/projectManagement'),
        meta: {title: '项目管理'},
      },
      {
        path: '/targetHospitalManagement',
        component: () => import('../views/projectManagement/targetHospitalManagement'),
        meta: {title: '目标医院管理'},
        hidden: true
      },
      {
        path: '/projectDoctorManagement',
        component: () => import('../views/projectManagement/projectDoctorManagement'),
        meta: {title: '项目医生管理'},
      },
    ]
  },
  //知识库
  {
    path: '/knowledgeBase',
    component: Layout,
    redirect:'/questionBankManagement',
    meta: {title: '知识库', icon: 'el-icon-chat-line-round'},
    children: [
      {
        path: '/questionBankManagement',
        component: () => import('../views/knowledgeBase/questionBankManagement'),
        meta: {title: '题库管理'},
      },
    ]
  },
  //运营活动管理
  {
    path: '/operationActivityManagement',
    component: Layout,
    redirect:'/articleManagement',
    meta: {title: '运营活动管理', icon: 'el-icon-chat-line-round'},
    children: [
      {
        path: '/articleManagement',
        component: () => import('../views/operationActivityManagement/articleManagement'),
        meta: {title: '文章管理'},
      },
      {
        path:'/addArticleManagement',
        component:()=>import('../views/operationActivityManagement/addArticle.vue'),
        meta:{title:'新增文章'},
        hidden:true
      },
      {
        path:'/editArticleManagement',
        component:()=>import('../views/operationActivityManagement/editArticle.vue'),
        meta:{title:'编辑文章'},
        hidden:true
      },
      {
        path: '/liveBroadcastManagement',
        component: () => import('../views/operationActivityManagement/liveBroadcastManagement'),
        meta: {title: '直播管理'},
      },
      {
        path:'/editLiveBroadcastManagement',
        component:()=>import('../views/operationActivityManagement/editLive.vue'),
        meta:{title:'编辑直播'},
        hidden:true
      },
      {
        path: '/onDemandManagement',
        component: () => import('../views/operationActivityManagement/onDemandManagement'),
        meta: {title: '点播管理'},
      },
      {
        path:'/editDemandManagement',
        component:()=>import('../views/operationActivityManagement/editDemand.vue'),
        meta:{title:'编辑点播'},
        hidden:true
      },
      {
        path: '/questionnaireManagement',
        component: () => import('../views/operationActivityManagement/questionnaireManagement'),
        meta: {title: '问卷管理'},
      },
      {
        path:'/editQuestionnaireManagement',
        component:()=>import('../views/operationActivityManagement/editQuestion.vue'),
        meta:{title:'编辑问卷'},
        hidden:true
      }
    ]
  },
];

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
